from django.db import models


class SoftDeletionManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(is_deleted=False)


class SoftDeletionModel(models.Model):
    """逻辑删除基类"""

    is_deleted = models.BooleanField(default=False, verbose_name='是否逻辑删除')

    all_objects = models.Manager()
    objects = SoftDeletionManager()

    class Meta:
        abstract = True


class CreateUpdateModel(SoftDeletionModel):
    """创建编辑模型"""

    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    create_user = models.CharField(max_length=64, null=True, blank=True, verbose_name="创建人")

    class Meta:
        abstract = True
